package com.common.android.utils;

import java.util.Random;
/**
 * 票据相关工具类
 * <br>Created 2014-8-26 上午11:17:13
 * @version  
 * @author   huangyx		
 * @see 	 
 * Copyright(c) 2009-2014, TQ Digital Entertainment, All Rights Reserved
 *
 */
public class BlowfishUtils {
    private static final int MIN_LEN = 16;
    private static final int MAX_LEN = 255;
    private static final int LETTER_CONUT = 26;
    
    /**
     * 生成票据的验证码
     * <br>Created 2014-8-22 上午10:34:07
     * @return 票据的验证码
     * @author       huangyx
     */
	public static  String getBlowFish(){
		return getBlowFish(MIN_LEN, MAX_LEN);
	}
	
	/**
	 * 生成票据的验证码(16-64)
	 * <br>Created 2014-8-26 上午11:17:42
	 * @param minlength 最大长度
	 * @param maxlength 最小长度
	 * @return 票据的验证码
	 * @author       huangyx
	 */
	public static  String getBlowFish(int minlength, int maxlength){
		Random rd = new Random();
		int length = 0;
		while(length < minlength){
			length = rd.nextInt(maxlength);
		}
		StringBuffer  buf = new StringBuffer(length);
		char a = 'a';
		for(int index = 0;index < length;index++){
			buf.append((char)(a + rd.nextInt(LETTER_CONUT)));
		}
		return buf.toString();
	}
}